package com.hello.service.impl;

import java.util.Date;
import java.util.List;

import com.helloblog.dao.UserDao;
import com.helloblog.dao.impl.ArticleDaoImpl;
import com.helloblog.dao.impl.BlogDaoImpl;
import com.helloblog.dao.impl.UserDaoImpl;
import com.helloblog.domain.Article;
import com.helloblog.domain.Blog;
import com.helloblog.domain.User;

public class CoreSerivceImpl {
	public void registe(User user){
		UserDao userDao = new UserDaoImpl();
		userDao.addUser(user);
	}
	public User login(String username,String password){
		UserDao userDao = new UserDaoImpl();
		return userDao.loginUser(username, password);
	}
	public void updateUserLoginInfo(String id,Date datetime,String ip){
		UserDao userDao = new UserDaoImpl();
		userDao.updateLastLoginInfo(id, datetime, ip);
	}
	/*
	 * 提供发布文章方法
	 */
	public void releaseArticle(Article a){
		ArticleDaoImpl articleDao = new ArticleDaoImpl();
		articleDao.addArticle(a);
	}
	
	/*
	 * 
	 * 提供列出所有博客文章的方法
	 */
	public List<Article> listAllArticle(){
		ArticleDaoImpl articleDao = new ArticleDaoImpl();
		return articleDao.listAllArticle();
	}
	
	/*
	 * 提供查看详细文章的方法
	 */
	public Article getArticle(String id){
		ArticleDaoImpl articleDao = new ArticleDaoImpl();
		return articleDao.getArticle(id);
	}
	
	/*
	 * 开通博客的方法
	 */
	public void openBlog(String id,Blog blog){
		UserDaoImpl userDao = new UserDaoImpl();
		BlogDaoImpl blogDao = new BlogDaoImpl();
		blogDao.openBlog(blog);
		userDao.updateWithOpenBlog(id);
	}
	/*
	 * 提供根据用户id查看文章的方法
	 */
	public List getArticlesByUserId(String user_id){
		ArticleDaoImpl articleDao = new ArticleDaoImpl();
		return articleDao.getArticlesByUserId(user_id);
	}
	/*
	 * 提供根据博客id查看文章的方法
	 */
	public List getArticlesByBlogId(String blog_id){
		ArticleDaoImpl articleDao = new ArticleDaoImpl();
		return articleDao.getArticlesByUserId(blog_id);
	}
	
	public User findUserByID(String userid){
		UserDao userDao = new UserDaoImpl();
		return userDao.findUserByID(userid);
	}
}
